


#ifndef _ROBOT_INTERACT_H_
#define _ROBOT_INTERACT_H_

#include "stdint.h"
#include "ringbuff.h"


#define CHARGE_TIME_ERRO_THD_S    4
#define PAIRED_CHECK_TIME_MS      2000

#define ROBOT_COMM_OVERTIEM_MS    3000

#define ID_ROBOT_ACK_FRAME        0x1800


typedef enum
{
	ENUM_UNPAIRED,
	ENUM_PAIRING,
	ENUM_PAIRED,
	ENUM_PAIR_FAULT

}ENUM_PAIR_STATUS;



typedef enum
{
	ROBOT_PAIR = 0x01,
	ROBOT_CTRL = 0x02

}ENUM_CMD_TYPE;



typedef union
{
	struct
	{
		uint8_t  type;
		uint8_t  fun_num;
		uint16_t ID_robot;
		uint16_t charge_time;
		
		uint8_t  pair_status;
		uint8_t  bat_soc;
		
	};
		
	uint8_t data[8];

}STR_INTE_PAIR_FRAME;


typedef union
{
	struct
	{
		uint8_t  type;
		uint8_t  fun_num;
		
		uint16_t ID_robot;
		
		uint8_t  en_actuate_X1  :1;
		uint8_t  en_actuate_X2  :1;
		uint8_t  en_waste_pump  :1;
		uint8_t  reserve1       :5;
		
		uint8_t  water_full     :1;
		uint8_t  sink_full      :1;
		uint8_t  waste_empty    :1;
		uint8_t  reserve2       :5;
		
		uint16_t reserve3;		
	
	};
	
	uint8_t data[8];

}STR_INTE_CTRL_FRAME;




typedef union
{

	struct
	{
		uint8_t  type;
		uint8_t  fun_num;
		
		uint16_t ID_station;
		uint16_t charge_time;
		
		uint8_t  pair_status;
		
		uint8_t  status_actuate_X1  :1;
		uint8_t  status_actuate_X2  :1;
		uint8_t  status_waste_pump  :1;
		uint8_t  waste_level_X1     :1;
		uint8_t  waste_level_X2     :1;
		
		uint8_t  reserve1           :3;
	
	};	
	
	uint8_t data[8];


}STR_INTE_ACK_FRAME;



typedef struct
{
	ENUM_PAIR_STATUS     pair_status;
	
	STR_INTE_PAIR_FRAME  pair;
	STR_INTE_CTRL_FRAME  ctrl;
	STR_INTE_ACK_FRAME   ack;
	
	uint16_t overtime_cnt;
	uint8_t  overtime_flg;
	
	uint16_t ID_station;

}STR_INTE_HDL;



extern STR_INTE_HDL robot_hdl;


extern void robot_interact_frame_init(void);

extern void robot_comm_data_handle(uint8_t *data_temp, STR_RINGBUF *sendbuf);

extern void robot_paried_handle(STR_INTE_HDL *robotHdl, uint16_t runtime_ms);

#endif




